package ;
import easelhx.display.Bitmap;
import easelhx.js.Image;
import easelhx.utils.Ticker;
import js.Lib;

/**
 * ...
 * @author 
 */

class SimpleTransformExample extends Example
{

	private var img:Image;
    private var angle:Float;
	private var bmp:Bitmap;
	
	public function new() 
	{
		super();
	}
	
	/* INTERFACE IExample */
	
	override public function run():Void 
	{
		angle = 0.0;
		img = new Image();
		img.onload = handleImageLoad;
		img.src = "assets/rotateDemoBot.png";
	}
	
	function stop() {
		Ticker.removeListener(this);
	}

	function handleImageLoad(event) {
		stage.autoClear = true;
		bmp = new Bitmap(img);
		bmp.regX = Std.int(img.width) >> 1;
		bmp.regY = Std.int(img.height) >> 1;
		bmp.x = Std.int(canvas.width - (img.width/2))>>1;
		bmp.y = Std.int(140+canvas.height - (img.height/2))>>1;
		bmp.scaleX = bmp.scaleY = 0.1;
		stage.addChild(bmp);
		stage.update();

		Ticker.addListener(this);
	}

	function tick() {
		angle += 0.025;
		var value = (Math.sin(angle) * 360);
		bmp.setTransform (bmp.x , bmp.y , bmp.scaleX , bmp.scaleY , value/2 , bmp.skewX , bmp.skewY , bmp.regX , bmp.regY );
		bmp.scaleX = bmp.scaleY = ((value)/360) + 0.25;
		//bmp.rotation = value;
		stage.update();
	}
	
}